<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>用户注册</title>
</head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<script type="text/javascript" th:src="@{/js/jquery.min.js}"></script>
<link rel="stylesheet" type="text/css" th:href="@{/bootstrap/css/bootstrap.min.css}"/>
<link rel="stylesheet" type="text/css" th:href="@{/static/css/login.css}"/>
<script type="text/javascript" th:src="@{/bootstrap/js/bootstrap.min.js}"></script>
<script type="text/javascript" th:src="@{/jquery-validation/jquery.validate.min.js}"></script>
<script type="text/javascript" th:src="@{/jquery-validation/localization/messages_zh.min.js}"></script>
<script type="text/javascript" th:src="@{/layer/layer.js}"></script>
<script type="text/javascript" th:src="@{/js/md5.min.js}"></script>
<script type="text/javascript" th:src="@{/js/common.js}"></script>
<body>
<div class="content">
    <div class="title">
        <h4>用户注册</h4>
    </div>

    <form name="RegisterForm" id="loginForm" method="post">
        <div class="form-group">
            <input id="username" name="username" class="form-control" type="text" placeholder="用户名" required="true"
            />

        </div>
        <div class="form-group">
            <input id="mobile" name="mobile" class="form-control" type="text" placeholder="手机号码" required="true"
                   minlength="11" maxlength="11"/>
        </div>

        <div class="form-group">
            <input id="password" name="password" class="form-control" type="password" placeholder="密码"
                   required="true" minlength="6" maxlength="16"/>
        </div>
        <div class="form-group">
            <input id="checkpassword" name="checkpassword" class="form-control" type="password" placeholder="确认密码"
                   required="true" minlength="6" maxlength="16"/>
        </div>
        <div class="form-group">
            <div class="form-inline">
                <input id="code" name="code" class="form-control" type="text" placeholder="验证码"
                       required="true">
                <img name="img" id="img" src="/code/image" title="看不清可单击图片刷新"
                     onclick="this.src='/code/image?d='+Math.random();" style="margin-bottom: -12px;">
            </div>
        </div>
        <div id="div1" name="div1">
            <span id="span1"></span>
        </div>
        <button class="btn btn-primary btn-block" type="button" onclick="to_registerquest()">确认注册</button>
    </form>
</div>

</body>
<script>
    function to_registerquest() {
        let mobile = $("#mobile").val();
        let username = $("#username").val();
        let password = $("#password").val();
        let checkpassword = $("#checkpassword").val();
        let code = $("#code").val();
        let salt = g_passsword_salt;
        let str1 = salt.charAt(0) + salt.charAt(2) + salt.charAt(4) + password;
        let str2 = salt.charAt(0) + salt.charAt(2) + salt.charAt(4) + checkpassword;
        let formPassword1 = md5(str1);
        let formPassword2 = md5(str2);
        let length = password.length;
        $.ajax({
            url: "/user/register",
            type: "POST",

            data: {
                mobile: mobile,
                username: username,
                password: formPassword1,
                checkpassword: formPassword2,
                code: code,
                passwordLength: length
            },
            success: function (data) {
                if (data.code == 0) {
                    window.location.href = "/goods/list";
                }
                console.log(data);
                $("#password").val("");
                $("#checkpassword").val("");
                $("#code").val("");
                $("#img").attr("src", "/code/image?timeamp=" + new Date().getTime());
                let html = "";
                html += data.msg;
                $("#span1").html(html);
            }
            ,
            error: function (data) {
                console.log(data);
                console.log("校验失败");
            }
        });

    }
</script>
</html>